package com.xintoucloud.pbs.service.impl;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xintoucloud.pbs.dao.RolePermissionDao;
import com.xintoucloud.pbs.entity.RolePermission;
import com.xintoucloud.pbs.model.RoleDto;
import com.xintoucloud.pbs.service.RolePermissionService;
@Service@Transactional
public class RolePermissionServiceImpl implements RolePermissionService{
	@Autowired
	private RolePermissionDao rolePermissionDao;
	
	@Override
	public List<RoleDto> list() {
		List<RoleDto> RoleDtos = new ArrayList<>();
		List<RolePermission> rolePermissions = rolePermissionDao.list();
				
		for (RolePermission rolePermission : rolePermissions) {
			RoleDto roleDto = new RoleDto();
			roleDto.setNid(rolePermission.getNid());
			roleDto.setRid(rolePermission.getRole().getRid());
			roleDto.setName(rolePermission.getRole().getName());
			roleDto.setParentId(rolePermission.getRole().getParentId_rid());
			roleDto.setPermission(rolePermission.getPmp().getPermission());
			RoleDtos.add(roleDto);
		}
		return RoleDtos;
	}

	@Override
	public Serializable save(RolePermission rolePermission) {
		return rolePermissionDao.save(rolePermission);
	}

	@Override
	public RolePermission getOne(int id) {
		return rolePermissionDao.getOne(id);
	}

	@Override
	public void delete(int id) {
		rolePermissionDao.delete(id);
	}

}
